<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>1-ajax简单封装</title>
  </head>
  <body>
    <ul>
      
    </ul>

    <script src="./ajax.js"></script>
    <script>
      ajax('http://localhost:8081/prodcuts/A?price=21').then(
        value => { // value是product对象组成的数组
          console.log(value)
          // 根据列表数据生成多个li标签的字符串
          const lis = value.reduce((pre, p) => pre + `<li>${p.id}--${p.name}--${p.price}</li>`, '')
          // 插入到ul
          const ul = document.querySelector('ul')
          ul.innerHTML = lis
        },
        error => {
          alert(error.message)
        }
      )
    </script>
  </body>
</html>
